﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CSharpDesign.DAL;
using CSharpDesign.Scripts;
using CSharpDesign.BLL;

namespace CSharpDesign.Admin
{
    public partial class ModifyPwd : System.Web.UI.Page
    {
        Alert alert = new Alert();
        SqlHelper data = new SqlHelper();
        ModifyPwdService pwdService = new ModifyPwdService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


            }
        }/// <summary>
         /// 修改密码
         /// </summary>
        private void UPpwd()
        {
            SqlHelper mydata = new SqlHelper();
            string Username = Session["AdminId"].ToString();
            string txtpwd2 = this.txtpwd2.Text.ToString();
            try
            {
                pwdService.UpdatePwd(Username, txtpwd2);

                LabelWarningMessage.Text = "修改成功！";


            }
            catch
            {

                LabelWarningMessage.Text = "修改失败！";
            }
        }

        /// <summary>
        /// 检验原来的密码
        /// </summary>
        private void chkpwd()
        {
            string adminId = Session["AdminId"].ToString();
            string txtpwd1 = this.txtpwd1.Text;
            SqlDataReader dr = pwdService.CheckPwd(adminId, txtpwd1);

            if (dr.Read())
            {
                UPpwd();
            }
            else
            {
                LabelWarningMessage.Text = "原密码不正确！";
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            chkpwd();
        }
    }

}